package com.wellsoft.mobileoa.utils.view;

import java.util.ArrayList;
import java.util.List;

import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;

import com.wellsoft.mobileoa.R;
import com.wellsoft.mobileoa.utils.BaseActivity;
import com.wellsoft.mobileoa.utils.BaseView;
import com.wellsoft.mobileoa.utils.BaseWidget;
import com.wellsoft.mobileoa.utils.view.RadioView.WSOA_PageList;
import com.wellsoft.mobileoa.wsmodel.WSOA_Page;
import com.wellsoft.mobileoa.wsmodel.WSOA_PageListSet;
import com.wellsoft.mobileoa.wsmodel.WSOA_PostField;

public class PostFailedView extends BaseView {
	public List<BaseWidget> widgetList;

	public PostFailedView(BaseActivity baseActivity, WSOA_Page page, String url) {
		super(baseActivity);
		this.baseActivity = baseActivity;
		this.page = page;
		this.url = url;
		widgetList = new ArrayList<BaseWidget>();

		if (page.getPageFields() != null && page.getPageFields().size() > 0) {
			for (int i = 0; i < page.getPageFields().size(); i++) {
				BaseWidget baseWidget = BaseWidget.createWidgetFactory(page
						.getPageFields().get(i), PostFailedView.this);
				if (baseWidget != null) {
					widgetList.add(baseWidget);
				}
			}
		}
	}

	@Override
	public ViewGroup DrawSelf() {
		LinearLayout l = new LinearLayout(baseActivity);
		l.setLayoutParams(new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		return l;
	}

	public BaseWidget getWidgetById(String widgetId) {
		for (int i = 0; i < widgetList.size(); i++) {
			if (widgetList.get(i).field.getFieldName() != null
					&& widgetList.get(i).field.getFieldName().equals(widgetId)) {
				return widgetList.get(i);
			}
		}
		return null;
	}

	@Override
	public List<WSOA_PostField> getValue() {
		List<WSOA_PostField> postFields = new ArrayList<WSOA_PostField>();
		for (BaseWidget widget : widgetList) {
			postFields.add(widget.getValue());
		}
		return postFields;
	}

}
